package com.ruoyi.ichen.rabbitmq.day4_direct;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.ruoyi.ichen.rabbitmq.common.RabbitMQUtils;

import java.io.IOException;

public class Provider {

    public static void main(String[] args) throws IOException {
        //获取连接对象
        Connection connection = RabbitMQUtils.getConnection();
        //获取通道对象
        Channel channel = connection.createChannel();
        //通过通道声明交换机 参数1：交换机名称 参数2：路由模式
        channel.exchangeDeclare("ichen_direct","direct");
        //发送消息
        String routingKey = "warnning";
        channel.basicPublish("ichen_direct",routingKey,null,("基于direct模式发布的routeKey:"+ routingKey + "发送的消息").getBytes());

        //关闭资源
        RabbitMQUtils.closeConnectionAndChannel(channel,connection);
    }
}
